/*
 * Copyright (C) 2009 Christoph Caks
 *
 * This file is part of GLWAK.
 *
 * GLWAK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GLWAK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GLWAK.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Window.h
 *
 *  Created on: 25.06.2009
 *      Author: Christoph Caks
 */

#ifndef WINDOW_H_
#define WINDOW_H_

#include <string>
#include <list>

#include "OpenGL.h"

#include "Disposable.h"
#include "Drawable.h"
#include "WindowConfiguration.h"
#include "handler/AbstractHandler.h"

namespace glwak {
	class Window;
}

#include "Context.h"

namespace glwak {

/**
 * represents an window.
 */
class Window : public Drawable {
public:

	Window();
	virtual ~Window();

	void setContext( Context *_context );

	/**
	 * sets the window configuration.
	 * <p>
	 * If the window is not yet initialized it just stores the configuration.
	 * If the window is already initialized the new configuration will be immediate activated.
	 * </p>
	 *
	 * @param _windowConfiguration
	 */
	virtual void setConfiguration( WindowConfiguration _windowConfiguration );

	virtual bool isInitialized();

	void initialize();

	virtual std::size_t getWindowHandle() = 0;

	virtual void show() = 0;
	virtual void hide() = 0;

	virtual void startMessageLoop() = 0;
	virtual void startMessageThread() = 0;

	void registerEventHandler( AbstractHandler* handler );
	void unregisterEventHandler( AbstractHandler* handler );

protected:
	WindowConfiguration configuration;
	Context *context;

	bool initialized;

	virtual void initializeImpl() = 0;

	virtual void reinitializeImpl() = 0;

	void dispatchOnResize( int width, int height );

	std::list<AbstractHandler*> handler;

};

} // namespace glwak

#endif /* WINDOW_H_ */
